<!DOCTYPE html>
<html lang="en">

<head>

    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta name="description" content="">
    <meta name="author" content="">

    <title></title>

    <!-- Bootstrap Core CSS -->
    <link href="__PUBLIC__/home/css/bootstrap.min.css" rel="stylesheet">

    <!-- Custom Fonts -->
    <!--<link href="_PUBLIC__/font/css/font-awesome.min.css" rel="stylesheet" type="text/css">-->

    <!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
    <!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
    <!--[if lt IE 9]>
        <script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script>
        <script src="https://oss.maxcdn.com/libs/respond.js/1.4.2/respond.min.js"></script>
    <![endif]-->
	
	<link href="__PUBLIC__/home/css/common.css" rel="stylesheet">
</head>

<body>
	<div class="container-fluid">
        <!-- Page Heading -->
        <div class="row">
			<div class="col-md-12">
				<ol class="breadcrumb">
					<li class="active">
						<i class="fa fa-fw fa-edit"></i>
						指令
					</li>
				</ol>
			</div>
		</div>
        <div class="row">
            <div class="col-lg-12">
                <!--<h4 class="page-header">
                	柠檬照相馆
                </h4>-->
                <div class="row">
					<div class="col-xs-12">
						<button data-toggle="modal" data-target="#myOperationModal" type="button" class="btn btn-sm btn-success op-btn" id="xx-btn-add"><span class="glyphicon glyphicon-plus" aria-hidden="true"></span>新增</button>
						<button data-toggle="modal" data-target="#myOperationModal" type="button" class="btn btn-sm btn-danger op-btn" id="xx-btn-all"><span class="glyphicon glyphicon-pencil" aria-hidden="true"></span>全选</button>
						<button data-toggle="modal" data-target="#myOperationModal" type="button" class="btn btn-sm btn-primary op-btn" id="xx-btn-delete"><span class="glyphicon glyphicon-folder-open" aria-hidden="true"></span>删除</button>
					</div>
					
				</div>
                
            </div>
        </div>
        <!-- /.row -->

        <div class="row">
            <div class="col-lg-12">
                <h2></h2>
                <div class="">
                    <table class="table table-bordered table-hover table-striped" id="dataTables-date">
                        <thead>
                            <tr>
                            	<th style="display: none;"></th>
                                <th>选择</th>
                                <th>id</th>
                                <th>指令</th>
                                <th class="operation-col">修改</th>
                            </tr>
                        </thead>
                       <tbody>
							
						</tbody>
                    </table>
                </div>
            </div>
        </div>
        <!-- /.row -->
        

    </div>
    
	

    <script src="__PUBLIC__/home/js/jquery.min.js"></script>

    <!-- Bootstrap Core JavaScript -->
    <script src="__PUBLIC__/home/js/bootstrap.min.js"></script>
    
    <!-- iframe自适应高度 -->

</body>
	<script type="text/javascript">
		var checkBox = false;
		
		$(function(){
			$.ajax({
				type:"post",
				url:"{:U('Drive/getDriveList')}",
				async:true,
				data:{
					
				},
				dataType:"json",
				success:function(result){
					if(result.code == 0){
						alert(result.msg);
					}else{
						var html = '';
						for(var i in result.data){
							html += 
								'<tr>'+
									'<td><input type="checkbox"/></td>' +
									'<td>'+result.data[i].drive_id+'</td>' +
									'<td>'+result.data[i].drive_name+'</td>'+
									'<td><button type="button" class="btn btn-sm btn-primary op-btn" onclick="checkRevise(this)" attr-id='+result.data[i].drive_id+'><span class="glyphicon glyphicon-folder-open" aria-hidden="true"></span>修改</button></td>'+
								'</tr>'
						}
						$("#dataTables-date tbody").append(html);
						
					}
				}
			
			});
			//图片预览事件
			$('.previous-img > img').on('click', function(){
				var current_img_url = $(this).attr('src');
				$('#aimBiggerImg').attr('src', current_img_url);
			});
			
			//顶部操作按钮事件
			$('.op-btn').on('click', function(){
				var current_btn_type = $(this).text();
				$('#myOpModalLabel').text(current_btn_type);
				
			});
			
			
			
		});
		
		$("#xx-btn-add").click(function(){
			location.href = "{:U('Drive/insert')}";
		});
		
		function checkRevise(obj){
			location.href = "{:U('Drive/revise')}?drive_id="+$(obj).attr('attr-id');
		}
		
		$("#xx-btn-all").click(function(){
			if(checkBox){
				$("input[type='checkbox']").each(function() {  
                    this.checked = false;  
                });  
                checkBox = false; 
                this.innerHTML = "<span class='glyphicon glyphicon-pencil' aria-hidden='true'></span>全选";
			}else {  
                $("input[type='checkbox']").each(function() {  
                    this.checked = true;  
                });  
                checkBox = true;
                this.innerHTML = "<span class='glyphicon glyphicon-pencil' aria-hidden='true'></span>取消";
            }  
		});
		$("#xx-btn-delete").click(function(){
			var deleteArray = [];
			$("input[type='checkbox']:checked").each(function() { // 遍历选中的checkbox
				deleteArray.push($(this).attr('attr-id'));
	       });
	       	if(!isNullStr(deleteArray)){
	       		swal({
					title: '确定要删除吗？',
					type: 'warning',
					showCancelButton: true,
					confirmButtonText: '确认删除',
					cancelButtonText: '取消操作',
					confirmButtonClass: 'btn btn-success dismissed-btn',
					cancelButtonClass: 'btn btn-danger dismissed-btn',
					buttonsStyling: false
				},(function(isConfirm) {
					if(isConfirm){
						$.ajax({
							type:"post",
							url:"__MODULE__/Admin/delete",
							data:{'all':deleteArray},
							dataType:'json',
							success:function(result){
								//链接服务器其成功
								if(result.status == SUCCESS){
									//成功
									return location.href = "__MODULE__/Admin/index";
								}else if (result.status == VALIDATE_ERROR){
									//表单验证出错
									var errors = result.msg;
									$('.zyn-p-validate-result').each(function(){
										var errorMsg = errors[$(this).attr('attr-validate')];
										$(this).html(errorMsg != undefined ? '*'+errorMsg : '').css({color:'red'});
									});
								}else{
								}
								
							},
						
						});
					}
				}));
	       		
	       	}
	        
		});
		
	</script>

</html>
